#! /bin/sh

# exit when any command fails
set -e

# create namespaces
ip netns add net0
ip netns add net1

# create a virtual ethernet interface in each namespace, assign IP addresses to them and bring them up
ip link add veth0 netns net0 type veth peer name veth1 netns net1
ip netns exec net0 ip addr add 192.168.2.1 dev veth0
ip netns exec net1 ip addr add 192.168.2.2 dev veth1
ip netns exec net0 ip link set veth0 up
ip netns exec net1 ip link set veth1 up

# add routes
ip netns exec net0 route add -net 192.168.2.0 netmask 255.255.255.0 dev veth0
ip netns exec net1 route add -net 192.168.2.0 netmask 255.255.255.0 dev veth1

# add delay+loss+corruption to veth0 interface
ip netns exec net0 tc qdisc add dev veth0 root netem loss 1% corrupt 5% delay 10ms 1ms
